﻿using System.Collections.Generic;
using System.Diagnostics.Contracts;
using Microsoft.Xna.Framework;
using ThinkDotNetBotApiCommon;
using ThinkDotNetBotApiCommon.Weapons;

namespace ThinkDotNetEngine.Bots
{
    public class BotController:IBotController
    {
        #region Constructors        

        public void Init(TankBot tankBot)
        {
            _tankBot = tankBot;
        }

        #endregion

        #region Fields

        private TankBot _tankBot;

        #endregion        

        #region IBotCommandsFacade Members

        public void Move(Vector3 destinationPos)
        {
            _tankBot.Move(destinationPos);
        }
        public void Stop()
        {
            _tankBot.Stop();
        }
        public void MoveTurret(float value)
        {
            _tankBot.MoveTurret(value);
        }
        public void MoveCannon(float value)
        {
            _tankBot.MoveCannon(value);
        }
        public Vector3 CurrentPosition
        {
            get { return _tankBot.Translation; }
        }      
        public IWeaponBase CurrentWeapon
        {
            get { return _tankBot.CurrentWeapon; }
        }

        public IScanableItem[] Scan(float radius)
        {
            return _tankBot.ScanObjects(radius);
        }

        public float TurretRotation
        {
            get { return _tankBot.TurretRotation; }
        }

        public void GetCannonParameters(out Vector3 centerPos, out Vector3 cannonForward)
        {
            centerPos = _tankBot.GetCannonPos();
            cannonForward = _tankBot.GetCannonForward();
        }
        public bool IsMoving
        {
            get { return _tankBot.IsMoving; }
        }
        public bool IsTurretReady
        {
            get { return _tankBot.IsTurretReady; }
        }
        public float CannonRotation
        {
            get { return _tankBot.CannonRotation; }
        }
        public bool IsCannonReady
        {
            get { return _tankBot.IsCannonReady; }
        }
        public Vector3 Forward { get { return -_tankBot.WorldMatrix.Forward; } }
        public Vector3 Translation
        {
            get { return _tankBot.Translation; }
        }
        public float RotationY
        {
            get { return _tankBot.RotationY; }
        }
        public bool LaunchAmmo()
        {
            return _tankBot.LaunchAmmo();
        }
        public bool ChangeWeapon(CannonWeaponType cannonWeaponType)
        {
            return _tankBot.ChangeWeapon(cannonWeaponType);
        }
        public IDictionary<CannonWeaponType, IWeaponBase> GetAllWeapons()
        {
            return _tankBot.AllWeapons;
        }
        public void LaunchTacticalMissile(Vector3 destination)
        {
            _tankBot.LaunchTacticalMissile(destination);
        }
        #endregion

        [ContractInvariantMethod]
        private void Invariant()
        {
            Contract.Invariant(_tankBot != null);
        }

 }
}
